using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace BuildingBlocks.Infrastructure.Outbox;

public sealed class OutboxMessageConfiguration : IEntityTypeConfiguration<OutboxMessage>
{
    public void Configure(EntityTypeBuilder<OutboxMessage> builder)
    {
        builder.ToTable("outbox_messages");

        builder.HasKey(o => o.Id);

        builder.Property(o => o.Type).HasMaxLength(255).IsRequired();
        builder.Property(o => o.Content).IsRequired();
        builder.Property(o => o.OccurredOnUtc).IsRequired();
        builder.Property(o => o.ProcessedOnUtc);
        builder.Property(o => o.Error);

        builder.HasIndex(o => o.ProcessedOnUtc);
    }
}
